﻿//---------------------------16/04/18   樊--------------------
//--------------------------获取验证码60s---------------------
//------------------------------------------------------------

var wait=60;
function time(o) {
  if (wait == 0) {
   o.removeAttribute("disabled");   
   o.value="获取验证码";
   wait = 60;
  } else { 
 
   o.setAttribute("disabled", true);
   o.value="重新发送" + wait + "";
   wait--;
   setTimeout(function() {
    time(o)
   },
   1000)
  }
 }
document.getElementById("btn").onclick=function(){time(this);}
//---------------------------------以上------------------------

var app = angular.module('myRegister', []);
app.controller('myRegisterCtrl', function($scope) {
$scope.user = {userid:"", password:"",phone_code:""};
$scope.info = "";
$scope.canRegister = false;
$scope.getCode = {"disabled":"disabled","shows":"获取验证码"};

//判断电话长度，小于11位不可用
$scope.useridChanged = function(){
	if($scope.user.userid.length==11){
		$scope.getCode.disabled = "";
	}
} 
$scope.register = function(){
	//---------------------------16/04/17   樊-------------------------------
	//----------增加了前台页面的js判断，用户名密码等的输入格式规范-----------
	//-----------------------------------------------------------------------
	//重置div显示值
	$scope.info = "";
	//判断用户名是否为空                       
	if(/^$/.test($scope.user.userid)){
		$scope.info = "请输入手机号！";
		return false;
	}
	//判断用户名是否数字                       
	if(isNaN($scope.user.userid)){
		$scope.info = "手机号格式不正确！";
		return false;
	}	
	//判断用户名是否为11位                   
	if($scope.user.userid.length!=11){
		$scope.info = "请输入正确的手机号！";
		return false;
	}
	//判断验证码是否为空                       
	if(/^$/.test($scope.user.phone_code)){
		$scope.info = "请输入验证码！";
		return false;
	}
	/*//判断验证码是否为数字                       
	if(isNaN($scope.user.phone_code)){
		$scope.info = "验证码格式不正确！";
		return false;
	}*/
	//判断验证码是否为6位                   
	if($scope.user.phone_code.length!=6){
		$scope.info = "验证码输入错误！";
		return false;
	}
	//判断密码是否为空                       
	if(/^$/.test($scope.user.password)){
		$scope.info = "请输入密码！";
		return false;
	}
	//判断密码是否为空                       
	if($scope.user.password.length<6){
		$scope.info = "密码长度不能低于6位！";
		return false;
	}
	//判断密码是否为空
	if($scope.user.read){
		$scope.info = "请填写密码!!!";
		return false;
	}
	//---------------------------------以上-----------------------------------
	//---------------------------------提交注册信息-----------------------------
	useridIsExist($scope.user.userid,function(result){
		if(!result.result){
			addUser($scope.user.userid,$scope.user.password,function(result){
				if(result.result){
					alert("用户注册成功，返回登录页面。");
					window.location.href = '/';
				}else{
					alert("系统故障，注册失败!!")
				}				
			})
		}else{
			$scope.info = "该手机号已经注册，可以直接登录!!";
		}
	})

	
};
});